﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Text;

namespace EvaluationSystem.DAO
{
    public class EvaluationManager:DAO
    {
        public DataTable GetTabsByRoleName(string roleName)
        {
            string getTabsByRoleNameCommand = "select [Id],[TabName] from [Tabs] where [RoleName]=@RoleName order by [Id]";
            Dictionary<string, object> parameters = new Dictionary<string, object>(1);
            parameters["RoleName"] = roleName;
            return ExcuteCommandDataTable(getTabsByRoleNameCommand, parameters);
        }

        public DataTable GetSummaryByTabIdAndGroupName(string id, string[] groupName)
        {
            string getSummaryByTabIdCommand = "select [Id],[SummaryName] from [Summary] where [TabId]=@TabId ";
            StringBuilder sbGroupCondition = new StringBuilder();
            Dictionary<string, object> parameters = new Dictionary<string, object>(groupName.Length + 1);
            if (groupName.Length > 0)
            {
                sbGroupCondition.Append("and (");
            }
            for (int i = 0; i < groupName.Length; i++)
            {
                if (i == groupName.Length -1)
                {
                    sbGroupCondition.Append(string.Format(" [GroupName] = @GroupName{0} ",i));
                }
                else
                {
                    sbGroupCondition.Append(string.Format(" [GroupName] = @GroupName{0} or ", i));
                }
                parameters["GroupName" + i] = groupName[i];
            }
            if (groupName.Length > 0)
            {
                sbGroupCondition.Append(")");
            }
            
            parameters["TabId"] = id;
            return ExcuteCommandDataTable(getSummaryByTabIdCommand, parameters);
        }

        public DataTable GetTabsByRoleId(string roleId)
        {
            string GetTabsByRoleNameCommand = "select [Roles] from [Tabs] where [RoleId]=@RoleId";
            Dictionary<string, object> parameters = new Dictionary<string, object>(1);
            parameters["RoleId"] = roleId;
            return ExcuteCommandDataTable(GetTabsByRoleNameCommand, parameters);
        }
    }
}